import Mock from "mockjs";
//处理路径传参
import { parameteUrl } from "@/utils/query-param"

function ArrSet(Arr: any[], id: string): any[] {
    let obj: any = {}
    const arrays = Arr.reduce((setArr, item) => {
        obj[item[id]] ? '' : (obj[item[id]] = true && setArr.push(item))
        return setArr
    }, [])
    return arrays
}
/**
* @description: min ≤ r ≤ max  随机数
* @param {*} Min
* @param {*} Max
* @return {*}
*/
function RandomNumBoth(Min: any, Max: any) {
    var Range = Max - Min;
    var Rand = Math.random();
    var num = Min + Math.round(Rand * Range); //四舍五入
    return num;
}
//左中
export default [
    {
        url: "/bigscreen/countUserNum",
        type: "get",
        response: () => {
            const a = Mock.mock({
                success: true,
                data: {
                    offlineNum: 1336.4 ,
                    alarmNum:  766.5,
                    lockNum: 1276.9,
                    onlineNum: 1944.7
                }
            })
            a.data.totalNum = a.data.onlineNum + a.data.offlineNum + a.data.lockNum + a.data.alarmNum
            return a
        },
    },
    {
        url: "/bigscreen/countDeviceNum",
        type: "get",
        response: () => {
            const a = Mock.mock({
                success: true,
                data: {
                    alarmNum: '9879',
                    offlineNum: '1638',
                    totalNum: 232
                }
            })
            a.data.onlineNum = '694'
            return a
        }
    },
    //左下
    {
        url: "/bigscreen/leftBottom",
        type: "get",
        response: () => {
            const a = Mock.mock({
                success: true,
                data: {
                    "list": [
                        {
                            provinceName: "广东省惠州市博罗县G35济广高速龙溪收费站",
                            cityName: '',
                            countyName: "",
                            createTime: "2025-09-22 00:05:43",
                            deviceId: "6c512d754bbcd6d7cd86abce0e0cac58",
                            "gatewayno": 20050901101,
                            "onlineState": 1,

                        },
                        {
                            provinceName: "北京市丰台区丰台北路",
                            cityName: '',
                            countyName: "",
                            createTime: "2025-09-22 00:05:43",
                            deviceId: "6c512d754bbcd6d7cd86abce0e0cac58",
                            "gatewayno": 20050901201,
                            "onlineState": 1,

                        },
                        {
                            provinceName: "上海市浦东新区金湘路201弄2号楼B1层",
                            cityName: '',
                            countyName: "",
                            createTime: "2025-09-22 00:05:43",
                            deviceId: "6c512d754bbcd6d7cd86abce0e0cac58",
                            "gatewayno": 20050901001,
                            "onlineState": 1,

                        },
                        {
                            provinceName: "上海市徐汇区斜土路1223号1楼机房",
                            cityName: '',
                            countyName: "",
                            createTime: "2025-09-22 00:05:43",
                            deviceId: "6c512d754bbcd6d7cd86abce0e0cac58",
                            "gatewayno": 20050901002,
                            "onlineState": 1,

                        },
                        {
                            provinceName: "广东省广州市增城区广惠高速",
                            cityName: '',
                            countyName: "",
                            createTime: "2025-09-22 00:05:43",
                            deviceId: "6c512d754bbcd6d7cd86abce0e0cac58",
                            "gatewayno": 20050901102,
                            "onlineState": 1,

                        },
                        {
                            provinceName: "北京市朝阳区顺白路12号",
                            cityName: '',
                            countyName: "",
                            createTime: "2025-09-22 00:05:43",
                            deviceId: "6c512d754bbcd6d7cd86abce0e0cac58",
                            "gatewayno": 20050901202,
                            "onlineState": 1,

                        },
                        {
                            provinceName: "广东省广州市黄埔区广东科学城科丰路31号g10栋",
                            cityName: '',
                            countyName: "",
                            createTime: "2025-09-22 00:05:43",
                            deviceId: "6c512d754bbcd6d7cd86abce0e0cac58",
                            "gatewayno": 20050901103,
                            "onlineState": 1,

                        },
                        {
                            provinceName: "上海市黄浦区南京东路61号",
                            cityName: '',
                            countyName: "",
                            createTime: "2025-09-22 00:05:43",
                            deviceId: "6c512d754bbcd6d7cd86abce0e0cac58",
                            "gatewayno": 20050901003,
                            "onlineState": 1,

                        },
                        {
                            provinceName: "北京市东城区美术馆东街18号",
                            cityName: '',
                            countyName: "",
                            createTime: "2025-09-22 00:05:43",
                            deviceId: "6c512d754bbcd6d7cd86abce0e0cac58",
                            "gatewayno": 20050901203,
                            "onlineState": 1,

                        },
                        {
                            provinceName: "广东省广州市黄埔区神舟路768号4栋",
                            cityName: '',
                            countyName: "",
                            createTime: "2025-09-22 00:05:43",
                            deviceId: "6c512d754bbcd6d7cd86abce0e0cac58",
                            "gatewayno": 20050901104,
                            "onlineState": 1,

                        },
                        {
                            provinceName: "上海市虹口区场中路201号",
                            cityName: '',
                            countyName: "",
                            createTime: "2025-09-22 00:05:43",
                            deviceId: "6c512d754bbcd6d7cd86abce0e0cac58",
                            "gatewayno": 20050901004,
                            "onlineState": 1,

                        },
                        {
                            provinceName: "北京市朝阳区红军营东路6号",
                            cityName: '',
                            countyName: "",
                            createTime: "2025-09-22 00:05:43",
                            deviceId: "6c512d754bbcd6d7cd86abce0e0cac58",
                            "gatewayno": 20050901204,
                            "onlineState": 1,

                        },
                        {
                            provinceName: "广东省广州市黄埔区广东科学城科丰路31号金发科技园G25",
                            cityName: '',
                            countyName: "",
                            createTime: "2025-09-22 00:05:43",
                            deviceId: "6c512d754bbcd6d7cd86abce0e0cac58",
                            "gatewayno": 20050901105,
                            "onlineState": 1,

                        },
                        {
                            provinceName: "上海市杨浦区隆昌路619号9楼4楼203机柜",
                            cityName: '',
                            countyName: "",
                            createTime: "2025-09-22 00:05:43",
                            deviceId: "6c512d754bbcd6d7cd86abce0e0cac58",
                            "gatewayno": 20050901005,
                            "onlineState": 1,

                        },
                        {
                            provinceName: "北京市房山区体育场路28号",
                            cityName: '',
                            countyName: "",
                            createTime: "2025-09-22 00:05:43",
                            deviceId: "6c512d754bbcd6d7cd86abce0e0cac58",
                            "gatewayno": 20050901205,
                            "onlineState": 1,

                        },
                        {
                            provinceName: "广东省广州市黄埔区科丰路31号华南新材料创新园G6栋",
                            cityName: '',
                            countyName: "",
                            createTime: "2025-09-22 00:05:43",
                            deviceId: "6c512d754bbcd6d7cd86abce0e0cac58",
                            "gatewayno": 20050901106,
                            "onlineState": 1,

                        },
                        {
                            provinceName: "上海市杨浦区隆昌路619号9楼4楼204机柜",
                            cityName: '',
                            countyName: "",
                            createTime: "2025-09-22 00:05:43",
                            deviceId: "6c512d754bbcd6d7cd86abce0e0cac58",
                            "gatewayno": 20050901006,
                            "onlineState": 1,

                        }
                    ]
                }
            })
            return a
        }
    },
    //右上
    {
        url: "/bigscreen/alarmNum",
        type: "get",
        response: () => {
            const a = Mock.mock({
                success: true,
                data: {
                    dateList: ['2021-11', '2021-12', '2022-01', '2022-02', '2022-03', "2022-04"],
                    "numList|6": [
                        '@integer(0, 1000)'
                    ],
                    "numList2|6": [
                        '@integer(0, 1000)'
                    ]
                }
            })
            return a
        }
    },
    //右中
    {
        url: "/bigscreen/ranking",
        type: "get",
        response: () => {
            let num = Mock.mock({ "list|80": [{ value: "@integer(50,1000)", name: "@city()" }] }).list
            //   console.log("ranking",num);
            let newNum: any = [], numObj: any = {}
            num.map((item: any) => {
                if (!numObj[item.name] && newNum.length < 8) {
                    numObj[item.name] = true
                    newNum.push(item)
                }
            })
            let arr = newNum.sort((a: any, b: any) => {
                return b.value - a.value
            })
            let a = {
                success: true,
                data: arr
            }
            return a
        }
    },
    //右下
    {
        url: "/bigscreen/rightBottom",
        type: "get",
        response: () => {
            const a = Mock.mock({
                success: true,
                data: {
                    "list|40": [{
                        alertdetail: "@csentence(5,10)",
                        "alertname|1": ["水浸告警", "各种报警"],
                        alertvalue: "@float(60, 200)",
                        createtime: "2022-04-19 08:38:33",
                        deviceid: null,
                        "gatewayno|+1": 10000,
                        phase: "A1",
                        sbInfo: "@csentence(10,18)",
                        "terminalno|+1": 100,
                        provinceName: "@province()",
                        cityName: '@city()',
                        countyName: "@county()",
                    }],

                }
            })
            return a
        }
    },
    //安装计划
    {
        url: "/bigscreen/installationPlan",
        type: "get",
        response: () => {
            // 固定的6个城市数据
            const cities = ["上海", "广州", "杭州", "贵州", "重庆", "武汉"];
            const barData = [85, 72, 68, 45, 78, 63]; // 各城市安装进度
            const lineData = [120, 95, 88, 60, 105, 85]; // 各城市总计划数
            const rateData = [71, 76, 77, 75, 74, 74]; // 各城市完成率
            
            return {
                success: true,
                data: {
                    category: cities,
                    barData: barData,
                    lineData: lineData,
                    rateData: rateData
                }
            }
        }
    },
    {
        url: "/bigscreen/centerMap",
        type: "get",
        response: (options: any) => {
            let params = parameteUrl(options.url)
            //不是中国的时候
            if (params.regionCode && !["china"].includes(params.regionCode)) {
                const a = Mock.mock({
                    success: true,
                    data: {
                        "dataList|100": [
                            {
                                name: "@city()",
                                value: '@integer(1, 1000)'
                            }
                        ],
                        regionCode: params.regionCode,//-代表中国
                    }
                })
                return a
            } else {
                const a = Mock.mock({
                    success: true,
                    data: {
                        "dataList|12": [
                            {
                                name: "@province()",
                                value: '@integer(1, 1100)'
                            }
                        ],
                        regionCode: 'china',
                    }
                })
                // 去重
                a.data.dataList = ArrSet(a.data.dataList, "name")
                return a
            }
        }
    }
];

